package com.hspedu.collection_;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author Stringzhua
 * @Date 2024/3/10 20:18
 * description:
 */
public class CollectionExercise {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(new Dog("线条小狗", 5));
        list.add(new Dog("灰色小狗", 6));
        list.add(new Dog("爪爪", 10));

        //迭代器
        System.out.println("=====使用迭代器=====");
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object dog = iterator.next();
            System.out.println("dog = " + dog);
        }

        System.out.println("=====增强for循环=====");
        //增强for循环
        for (Object dog : list) {
            System.out.println("dog = " + dog);
        }

    }
}

class Dog {
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
